<?php
require_once 'Zend/Controller/Plugin/Abstract.php';
require_once realpath('../public/ckEditor/ckeditor.php');
/**
 * 结合CKEditor编辑器
 * 
 * Zend Framework 专用
 * 
 * @example
 * 直接再视图页面调用
 * <?php 
	$config = array();
	$ckeditor = new Custom_Controller_Plugin_CKEditor();
	echo $ckeditor->CKEditor('centner', $this->baseUrl(), null, $config);
	?>
 * 
 * @author 高强
 */
class Custom_Controller_Plugin_CKEditor extends Zend_Controller_Plugin_Abstract
{
	/**
	 * 用于生成CKEditor编辑器
	 * 
	 * @param string $ckName  编辑器名称
	 * @param string $baseUrl 基本路径
	 * @param string $value   当前值
	 * @param array $config   配置项
	 * 
	 * @return string
	 */
	public function CKEditor($ckName = null, $baseUrl = null, $value = null, array $config = array())
	{
		$ckEditor = new CKEditor();
		
		$ckEditor->returnOutput = true;
		$ckEditor->basePath = $baseUrl.'/ckEditor/';
		
		$config['removePlugins'] = 'save';
		$config['pasteFromWordRemoveStyles'] = true;
		
		$config['filebrowserBrowseUrl'] = $baseUrl.'/ckFinder/ckfinder.html';
		$config['filebrowserImageBrowseUrl'] = $baseUrl. '/ckFinder/ckfinder.html?Type=Images';
		$config['filebrowserFlashBrowseUrl'] = $baseUrl. '/ckFinder/ckfinder.html?Type=Flash';
		
		$config['filebrowserUploadUrl'] = $baseUrl. '/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files';
		$config['filebrowserImageUploadUrl'] = $baseUrl. '/ckFinder/core/connector/php/connector.php?command=QuickUpload&type=Images';

		
		$config['toolbar'] = array(
			array('Bold', 'Italic', 'Underline', 'Strike', '-', 'Subscript', 'Superscript'),
			array('NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', 'Blockquote'),
			array('JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'),
			array('Link', 'Unlink', 'Anchor', 'ShowBlocks', '-', 'Source'),
			array('Styles', 'Format', 'Font', 'FontSize', '-', 'TextColor', 'BGColor'),
			array('Image', 'Flash', 'Table', 'HorizontalRule')
		);
		
		$config['width'] = isset($config['width']) ? : 900;
		$config['height'] = isset($config['height']) ? : 500;
		
		return $ckEditor->editor($ckName, $value, $config);
	}
}